package com.example.demo.service.Impl;

import com.example.demo.ao.*;
import com.example.demo.mapper.SettingEquipmentMapper;
import com.example.demo.service.SettingEquipmentService;
import com.example.demo.vo.SettingEquipmentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SettingEquipmentServiceImpl implements SettingEquipmentService {


    @Autowired
    private SettingEquipmentMapper settingEquipmentMapper;


    @Override
    public int startTicket(SettingEquipmentUserAo settingEquipmentUserAo, SettingEquipmentEquipmentAo settingEquipmentEquipmentAo, SettingEquipmentWkorderAo settingEquipmentWkorderAo) {
        List<SettingEquipmentVo> settingEquipmentVos = settingEquipmentMapper.selectStartTicket(settingEquipmentUserAo);
        int total = 0;
        if (settingEquipmentVos == null || settingEquipmentVos.isEmpty()){
            SettingEquipmentVo settingEquipmentVo = settingEquipmentMapper.selectEquipment(settingEquipmentEquipmentAo);
            settingEquipmentWkorderAo.setEqId(settingEquipmentVo.getId());
            settingEquipmentWkorderAo.setStatus("02");
            if (settingEquipmentUserAo.getId() == 1){
                settingEquipmentWkorderAo.setPriority("02");
            }else if (settingEquipmentUserAo.getId() == 2){
                settingEquipmentWkorderAo.setPriority("01");
            }else {
                settingEquipmentWkorderAo.setPriority("03");
            }
            settingEquipmentWkorderAo.setSubTime(new Date());
            total = settingEquipmentMapper.startTicketWkOrder(settingEquipmentWkorderAo);
        }
        return total;

    }
}
